/*
 * Includes several utility definitions and header files
 */
#ifndef UTIL_H_
#define UTIL_H_

typedef unsigned char byte;

// Method that returns the element count inside an array
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(*(x)))
// The cpu frequenz
#define F_CRYSTAL 16000000

#include <util/delay.h>

#include "uart.h"
#include "sensor.h"
#include "steering.h"

// The LED port
#define LED PORTD
// The LED port pin
#define LED_PAD PORTD5
//The LED DDR
#define LED_DDR DDRD
//To be used with LED_On(int):void
#define LED_ON 1
//To be used with LED_On(int):void
#define LED_OFF 0

/**
 * Initializes the LED
 */
static inline void init_LED() {
	LED_DDR |= (1 << LED_PAD);
}

/**
 * Use LED_ON or LED_OFF to gain the wanted effect.
 */
static inline void LED_On(int on) {
	if ((on % 2) == 0) {// wenn gerade, dann ausschalten
		LED |= (1 << LED_PAD);
	} else { //sonst anschalten
		LED &= ~(1 << LED_PAD);
	}
}

extern void init_hardware();

#endif /*UTIL_H_*/
